package com.example.grafstock_cliente;

import android.app.Activity;
import android.os.Bundle;
import android.view.View;
import android.view.Window;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.FrameLayout;
import android.widget.ImageView;

import com.koushikdutta.ion.Ion;

public class MainActivity extends Activity {
	
	private WebView web;
	
	private String url = "54.186.251.237:8080";
	
    @Override
    public void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		requestWindowFeature(Window.FEATURE_NO_TITLE);
        setContentView(R.layout.activity_main);
        ImageView image = (ImageView) findViewById(R.id.imgCarregando);
        Ion.with(image).load("http://"+getUrl()+"/controle-cliente/assets/images/ajax-loader.gif");
        
		web = (WebView) findViewById(R.id.webView);
		WebSettings settings = web.getSettings();
		settings.setJavaScriptEnabled(true);
		settings.setJavaScriptCanOpenWindowsAutomatically(true);
		settings.setSupportMultipleWindows(true);
		settings.setSupportZoom(false);
		//settings.setPluginsEnabled(true);
		web.setVerticalScrollBarEnabled(true);
		web.setHorizontalScrollBarEnabled(false);
		web.setWebViewClient(new MyWebViewClient());
		web.loadUrl("http://"+getUrl()+"/controle-cliente/index.jsp");
	}

	private class MyWebViewClient extends WebViewClient {	    
		public boolean shouldOverrideUrlLoading(WebView v, String url) {
			return false;
		}
		@Override
		public void onPageFinished(WebView view, String url) {
			super.onPageFinished(view, url);
			FrameLayout frameLayout = (FrameLayout) findViewById(R.id.frameLoad);
			frameLayout.setVisibility(View.INVISIBLE);
			web.setVisibility(View.VISIBLE);
		}
	}    
	
	public String getUrl() {
		return url;
	}
	
}
